home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
13.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
30KB
|
1,044 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
#ifndef SEM
#define SEM 1
#endif
#include "hdr.h"
#include "vars.h"
#include "attr.h"
#include "setp.h"
#include "dclmapp.h"
#include "arithp.h"
#include "errmsgp.h"
#include "miscp.h"
#include "smiscp.h"
#include "chapp.h"
/* 13. Representation Clauses*/
#define max_val(x,y) ((x) > (y) ? (x) : (y))
#define rc_unset 0
#define rc_set 1
#define rc_default (-1)
#define storage_unit 32
#define padding 0
#define size_position 2
#define storage_size_position 4
#define small_position 4
#define pack_position 4
#define literal_map_position 4
#define alignment_position 6
/*
* Currently the representation information is structured as follows:
*
* integer & floating point types
* [size]
*
* task & access types
* [size, storage_size]
*
* fixed point types
* [size] -- small is kept in the symbol table as 5th entry of signature
*
* array types
* [size, pack]
*
* record types
* [size, pack, [modulus, [[field, pos, first_bit, last_bit],...]]]
*
* enumeration types
* [size, literal_map]
*
*/
static char *default_representation(Symbol, int);
static void apply_length_clause(int, Symbol, Node);
static void apply_enum_clause(Symbol, Tuple);
static void apply_record_clause(Symbol, int, Tuple);
static Tuple not_chosen_get(Symbol);
static void not_chosen_delete(Symbol);
static int default_size_value(Symbol);
static int component_size(Symbol);
static Tuple default_record_value(Symbol);
extern int ADA_MAX_INTEGER;
void initialize_representation_info(Symbol type_name, int tag)
/*;initialize_representation_info */
{
/*
* Initialize the representation information of the given type by setting
* all its fields to the status unset.
*/
Tuple rctup;
if (tag == TAG_RECORD) {
rctup = tup_new(7);
rctup[1] = (char *) tag;
rctup[2] = (char *) rc_unset;
rctup[4] = (char *) rc_unset;
rctup[6] = (char *) rc_unset;
}
else if (tag == TAG_TASK || tag == TAG_ACCESS ||
tag == TAG_ARRAY || tag == TAG_ENUM) {
rctup = tup_new(5);
rctup[1] = (char *) tag;
rctup[2] = (char *) rc_unset;
rctup[4] = (char *) rc_unset;
}
else { /* TAG_INT || TAG_FIXED */
rctup = tup_new(3);
rctup[1] = (char *) tag;
rctup[2] = (char *) rc_unset;
}
RCINFO(type_name) = rctup;
FORCED(type_name) = FALSE;
not_chosen_put(type_name, (Symbol)0);
}
void choose_representation(Symbol type_name)
/*;choose_representation(type_name)*/
{
Symbol b_type;
Tuple current_rep;
Tuple tup;
int status,i,n;
b_type = base_type(type_name);
current_rep = RCINFO(b_type);
if (current_rep == (Tuple)0) {
REPR(type_name) = (Tuple)0;
return;
}
n = tup_size(current_rep);
for (i=2; i<=n; i+=2) {
status = (int) current_rep[i];
if (status == rc_unset) {
current_rep[i] = (char *) rc_default;
current_rep[i+1] = (char *) default_representation(type_name,i);
}
}
tup = tup_new((n/2)+1);
tup[1] = current_rep[1];
for (i=1; i<=(n/2); i++) {
tup[i+1] = current_rep[2*i+1];
}
REPR(type_name) = tup;
}
void inherit_representation_info(Symbol derived_type, Symbol parent_type)
/*; inherit_representation_info */
{
Symbol b_type;
Symbol v_type;
Tuple current_rep;
int i,n;
/*
* A derived type inherits all the representation information of its parent.
* However, this information is only considered to have a status of a 'default'
* representation which may be overidden by an explicit representation clause
* given to the derived type. It is therefore necessary to change the status
* field of the derived type when the parent had the status of 'set'.
*/
/*
* If the parent type is private we must retrieve its base type from the
* private_decls entry
*/
if (TYPE_OF(parent_type) == symbol_private ||
TYPE_OF(parent_type) == symbol_limited_private) {
v_type = private_decls_get((Private_declarations)
private_decls(SCOPE_OF(parent_type)), parent_type);
/*
* Check to seem if vis_decl is defined before accessing it. It might be
* undefined in the case of compilation errors.
*/
if (v_type != (Symbol)0) {
b_type = TYPE_OF(v_type); /* TYPE_OF field in the symbol table */
}
else {
return;
}
}
else {
b_type = base_type(parent_type);
}
current_rep = RCINFO(b_type);
if (current_rep == (Tuple)0) {
return;
}
current_rep = tup_copy((Tuple)RCINFO(b_type));
n = tup_size(current_rep);
for (i=2;i<=n;i+=2) {
if ((int)current_rep[i] == rc_set) {
current_rep[i] = (char *) rc_default;
}
else if ((int) current_rep[i] == rc_unset) {
current_rep[i] = (char *) rc_default;
current_rep[i+1] = (char *) default_representation(derived_type,i);
}
}
RCINFO(derived_type) = current_rep;
FORCED(derived_type) = FALSE;
not_chosen_put(derived_type, (Symbol)0);
}
already_forced(Symbol type_name) /*; already_forced */
{
int result;
result = FORCED(type_name);
return result;
}
void force_representation(Symbol type_name) /*; force_representation */
{
Symbol b_type,r_type,v_type,sym;
Fortup ft1;
Tuple current_rep,tup,field_names;
int i,n;
b_type = base_type(type_name);
/* Check if type has already been forced. */
if (already_forced(b_type)) {
return;
}
else {
if (is_generic_type(b_type)) {
/*
* There is no need to force a generic formal type since any use of this
* type will refer to the generic actual parameter after the instantiation
* and therefore the representation information is just that of the actual.
* Subtypes of generic formal types will be handled differently with the
* 'delayed_repr' instruction generated in Subtype_Declaration.
*/
not_chosen_delete(b_type);
return;
}
#ifdef TBSL
else if (has_generic_component(b_type)) {
/* If a type has generic components its forcing must be delayed until
* the point of instantiation when the representation of the actuals are
* known, since the representation of the record or array is dependent on
* the representation of the generic components. The replace routine will
* choose the representation for all
* delayed reprs.
*/
delayed_reprs with:= b_type;
FORCED(b_type) = TRUE;
return;
}
#endif
FORCED(b_type) = TRUE;
current_rep = RCINFO(b_type);
if (current_rep == (Tuple)0) {
/* some sort of error condition */
not_chosen_delete(b_type);
return;
}
n = tup_size(current_rep);
for (i=2;i<=n;i+=2) {
if ((int)current_rep[i] == rc_default) {
current_rep[i] = (char *) rc_set;
}
}
RCINFO(b_type) = current_rep;
/*
* Force all component fields of the record type before the representation is
* decided for the record type since the component types may affect the size
* of the record.
*/
if (is_record(b_type)) {
r_type = root_type(type_name);
if (TYPE_OF(r_type) == symbol_private ||
TYPE_OF(r_type) == symbol_limited_private) {
v_type = private_decls_get((Private_declarations)
private_decls(SCOPE_OF(r_type)), r_type);
if (v_type == (Symbol)0) { /* error condition */
not_chosen_delete(b_type);
return;
}
field_names = build_comp_names((Node) invariant_part(v_type));
}
else {
field_names = build_comp_names((Node) invariant_part(b_type));
}
FORTUP(sym=(Symbol),field_names,ft1);
force_representation(TYPE_OF(sym));
ENDFORTUP(ft1);
}
choose_representation(b_type);
tup = not_chosen_get(b_type);
FORTUP(sym=(Symbol),tup, ft1);
choose_representation(sym);
ENDFORTUP(ft1);
not_chosen_delete(b_type);
}
}
void force_all_types() /*; force_all_types */
{
Symbol b_type;
/*
* Called at the end of a declarative part, to force all types not already
* affected by a forcing occurence.
*/
while (tup_size(NOT_CHOSEN) > 0) {
b_type = (Symbol) NOT_CHOSEN[1];
force_representation(b_type);
}
}
stat